//
// Created by 123 on 2022/11/7.
//
#include"piles.h"
#include <algorithm>

class Card;

void Pile::addACard(const Card &card) {
    cards.push_back(const_cast<Card *>(&card));
}

void Pile::deleteACard(const Card &card) {   //玩家在牌堆中获得卡牌
    bool flag = false;
    auto it = cards.begin();
    for (; it != cards.end(); it++) {
        if (**it == card) {
            flag = true;
            break;
        }
    }
    if (flag) {
        cards.erase(it);  //删除牌堆中的牌
    }
}

unsigned int OrdinaryBuildings::numOfOrdinaryBuildings = 84;
unsigned int LandmarkBuildings::numOfLandmarkBuildings = 16;

BaseBuildings::BaseBuildings() : Pile() {
    for (size_t i = 0; i < 8; i++) {
        Pile::addACard(CardsTab::getInstance().getCard(i));
    }
}

LandmarkBuildings::LandmarkBuildings() : Pile() {
    for (size_t i = 8; i < 8 + 16; i++) {
        Pile::addACard(CardsTab::getInstance().getCard(i));
    }
}

void LandmarkBuildings::deleteACard(const Card &card) {
    Pile::deleteACard(card);
    numOfLandmarkBuildings--;
}

void LandmarkBuildings::printAllCards(ostream &o) {
    int i = 1;
    for (auto it = cards.begin(); it != cards.end(); it++) {
        o << i << ") " << *(*it) << "\t";
        if (i % 5 == 0) o << "\n";   //每显示5张卡片换行
        i++;
    }
}

OrdinaryBuildings::OrdinaryBuildings() : Pile() {
    for (size_t i = 8 + 16; i < 8 + 16 + 84; i++) {
        addACard(CardsTab::getInstance().getCard(i));
    }
}

void OrdinaryBuildings::deleteACard(const Card &card) {
    Pile::deleteACard(card);
    numOfOrdinaryBuildings--;
}

void OrdinaryBuildings::printAllCards(ostream &o) {
    unsigned int i = LandmarkBuildings::numOfLandmarkBuildings + 1;
    for (auto it = cards.begin(); it != cards.end(); it++) {
        o << i << ") " << *(*it) << "\t";
        if (i % 5 == 0) o << "\n";   //每显示5张卡片换行
        i++;
    }
}

